package com.orange.adminapi.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orange.core.pojo.entity.activityRegistration.ActivityRegistration;
import com.orange.core.pojo.enums.PaymentStatus;
import com.orange.core.pojo.enums.PaymentTypeEnums;
import com.orange.core.service.activityRegistration.ActivityRegistrationService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * <p>ClassName:ActivityRegistrationTaskJobHandler</p>
 * <p>Description: 活动人员任务</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/7/15 22:17</p>
 */
@Slf4j
@RequiredArgsConstructor
@Component
public class ActivityRegistrationTaskJobHandler {

    private final ActivityRegistrationService activityRegistrationService;

    /**
     * 修改超过30分未支付活动费用的订单
     * @param param
     * @return
     */
    @XxlJob("activityRegistrationTask")
    public ReturnT<String> activityRegistrationTask(String param) {
        log.info("开始修改超过30分未支付活动费用的订单任务");
        LambdaQueryWrapper<ActivityRegistration> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ActivityRegistration::getIsPaid, PaymentStatus.NOT_PAID);
        queryWrapper.le(ActivityRegistration::getCreateTime, LocalDateTime.now().minusMinutes(30));
        ActivityRegistration activityRegistration = new ActivityRegistration();
        activityRegistration.setIsPaid(PaymentStatus.CANCELLED);
        activityRegistrationService.update(activityRegistration, queryWrapper);
        log.info("开始修改超过30分未支付活动费用的订单任务完成");
        return ReturnT.SUCCESS;
    }
}
